import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart' show LoadMoreViewBuilder;

LoadMoreViewBuilder loadMoreBuilder = (context, loadMoreRows) {
  Future<String> loadRows() async {
    await loadMoreRows();
    return Future<String>.value('Completed');
  }

  return FutureBuilder<String>(
    initialData: 'loading',
    future: loadRows(),
    builder: (context, snapShot) {
      if (snapShot.data == 'loading') {
        return Container(
            height: 98.0,
            color: Colors.white,
            width: double.infinity,
            alignment: Alignment.center,
            child:
                CircularProgressIndicator(valueColor: AlwaysStoppedAnimation(Colors.deepPurple)));
      } else {
        return SizedBox.fromSize(size: Size.zero);
      }
    },
  );
};

LoadMoreViewBuilder loadMoreStatefulBuilder = (context, loadMoreRows) {
  bool showIndicator = true;
  return StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
    if (showIndicator) {
      return Container(
          height: 98.0,
          color: Colors.white,
          width: double.infinity,
          alignment: Alignment.center,
          child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation(Colors.deepPurple)));
    } else {
      return Container(
        height: 98.0,
        color: Colors.white,
        width: double.infinity,
        alignment: Alignment.center,
        child: Container(
          height: 36.0,
          width: 142.0,
          color: Colors.deepPurple,
          child: TextButton(
            //  color: Colors.deepPurple,
            child: Text('LOAD MORE', style: TextStyle(color: Colors.white)),
            onPressed: () async {
              if (context is StatefulElement && context.state.mounted) {
                setState(() {
                  showIndicator = true;
                });
              }
              await loadMoreRows();
              if (context is StatefulElement && context.state.mounted) {
                setState(() {
                  showIndicator = false;
                });
              }
            },
          ),
        ),
      );
    }
  });
};
